1. Field of the Invention
The present invention generally relates to a nonvolatile semiconductor memory unit employing a nonvolatile semiconductor memory and more particularly, to a technique for preventing fatal data contamination due to sudden disconnection of a power source in the nonvolatile semiconductor memory unit.
2. Description of the Prior Art
As nonvolatile semiconductor memory units, compact flash memory cards employing flash memories, for example, a flash AT Attachment (ATA) card and a xe2x80x9cCompactFlashxe2x80x9d (trade name) card are widely used. Since the flash memories are nonvolatile memories, data of the flash memories is held even if their power sources are disconnected. Thus, the flash memories are widely diffused as removable media which can be easily removably inserted into these flash memory cards. In the flash memories employed in these cards, data write and data erase are performed by electron injection and electron emission at a floating gate. Data write and data erase are performed in various methods. However, generally, if control of electric charge is performed erroneously, such an inconvenience is incurred that data of an identical block cannot be accessed due to a configuration of a memory array, so that the utmost care is exercised in control of electric charge.
Conventionally, when a power source of the card has been disconnected in the course of complicated control of electric charge during data write or data erase in the flash memory by erroneously removing the card from an electronic appliance acting as a host, for example, a terminal unit, such a problem may arise that data of a corresponding block cannot be accessed due to abnormal state of electric charge.
The above problem can be avoided if the card user removes the card from the host after having confirmed that the card is in a ready state. However, in case the power source of the card has been disconnected by sudden service interruption, short break or the like, the above problem cannot be avoided.
Accordingly, an essential object of the present invention is to provide, with a view to eliminating the above mentioned drawbacks of prior art, a nonvolatile semiconductor memory unit in which fatal data contamination does not happen even if its power source is disconnected suddenly during its operation.
In order to accomplish this object of the present invention, a nonvolatile semiconductor memory unit which is provided with a nonvolatile semiconductor memory and a control means for performing a read operation, a write operation and an erase operation on the nonvolatile semiconductor memory unit, according to the present invention includes an external power source which derives its supply of electric power from outside. An internal power source derives its supply of electric power from a secondary battery and is connected to the nonvolatile semiconductor memory and the control means. A voltage detecting circuit detects a voltage of the external power source, while a switching circuit is provided between the external power source and the internal power source and is subjected to on-off control by an output of the voltage detecting circuit so as to enable and disable the external power source, respectively. When the voltage detecting circuit has detected that the voltage of the external power source is lower than a predetermined level, an output signal of the voltage detecting circuit not only is inputted, as an interrupt signal, to the control means but is inputted, as an off-state signal, to the switching circuit. The internal power source is actuated by the secondary battery for a predetermined period after the eternal power source has been disabled by the switching circuit turned off by the off-state signal. In response to the interrupt signal, the control means calls an interruption handling routine in which not only in write and erase of the nonvolatile semiconductor memory, only the write operation and the erase operation under way in the nonvolatile semiconductor memory are completed properly but by recording in the nonvolatile semiconductor memory a flag indicating that a processing has been interrupted by disconnection of the external power source and contents of residual processings to be executed, data of the nonvolatile semiconductor memory can be restored when the external power source is recovered later.